import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

/**
 *
 * @author Bora SAYINER
 * @since Dec 21, 2014 10:12:51 AM
 * @version 1.0
 */
public class Driver {

	public static void main(String[] args) {
		ShapePanel shapePanel;
		JFrame frmMain = new JFrame();
		frmMain.setTitle("Border Layout");
		frmMain.setSize(400, 400);
		frmMain.setLocationRelativeTo(null);
		frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		{
			// MyPanel myPanel = new MyPanel();
			//
			// frmMain.add(myPanel, BorderLayout.CENTER);
		}
		{
			shapePanel = new ShapePanel();

			frmMain.add(shapePanel, BorderLayout.CENTER);
		}
		{
			JPanel pnlSouth = new JPanel();
			{
				{
					JButton btnAddRectangle = new JButton("Rectangle");
					btnAddRectangle.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							Random random = new Random();
							Rectangle rectangle = new Rectangle(random.nextInt(350), random.nextInt(350), 20);
							shapePanel.addShape(rectangle);
						}
					});
					pnlSouth.add(btnAddRectangle);
				}
				{
					JButton btnAddCircle = new JButton("Circle");
					btnAddCircle.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							Random random = new Random();
							Circle circle = new Circle(random.nextInt(350), random.nextInt(350), 15);
							shapePanel.addShape(circle);
						}
					});
					pnlSouth.add(btnAddCircle);
				}
				{
					Timer timer = new Timer(500, new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							Random random = new Random();
							int nextInt = random.nextInt(10);
							if (nextInt % 2 == 0) {
								Rectangle rectangle = new Rectangle(random.nextInt(350), random.nextInt(350), 20);
								shapePanel.addShape(rectangle);
							} else {
								Circle circle = new Circle(random.nextInt(350), random.nextInt(350), 15);
								shapePanel.addShape(circle);
							}
						}
					});
					JButton btnRandomShape = new JButton("Random Shape");
					btnRandomShape.addActionListener(new ActionListener() {
						@Override
						public void actionPerformed(ActionEvent e) {
							timer.start();
						}
					});
					pnlSouth.add(btnRandomShape);
				}
				{
					JButton btnDeleteShape = new JButton("Delete Shape");
					btnDeleteShape.addActionListener(new ActionListener() {
						
						@Override
						public void actionPerformed(ActionEvent e) {
							shapePanel.removeShape();
						}
					});
					pnlSouth.add(btnDeleteShape);
				}
			}
			frmMain.add(pnlSouth, BorderLayout.SOUTH);
		}
		frmMain.setVisible(true);
	}
}
